{include file="common/header"/}

<body class="bg-light">
	<div class="container">
		<div class="col-md-8">
			<div class="card text-center my-4">
				{notempty name="user"}
				<img src="__AVATOR__{$user.avator_path}" class="img-circle img-lg mx-auto my-3">
				<h5 class="mb-3"><strong>{$user.fullname}</strong></h5>
				<p class="mb-1">{$user.introduction}</p>
				<p class="mb-1"><i class="fa fa-calendar"></i>&nbsp;<small>{$user.create_time}</small></p>
				<ul class="nav nav-tabs justify-content-center mt-4" role="tablist">
					<li class="nav-item">
						 <a class="nav-link active" id="text_tab" data-toggle="tab" href="#text" role="tab" aria-controls="text" aria-selected="true">我的内容</a>
					</li>
					<li class="nav-item">
						 <a class="nav-link" id="reply_tab" data-toggle="tab" href="#reply" role="tab" aria-controls="reply" aria-selected="false">我的回复</a>
					</li>
				</ul>
				{/notempty}
			</div>
			<div class="tab-content">
				{notempty name="texts"}
				<div class="tab-pane fade show active" id="text" role="tabpanel" aria-labelledby="text_tab">
					{foreach $texts as $text}
					<div class="card my-4">
						<div class="card-body">
							<div class="media">
								<img src="__AVATOR__{$text.user.avator_path}" class="img-circle img-md">
								<div class="media-body ml-2">
									<div class="float-right">
										{if condition="$text.user.id == $Think.session.user_id or $Think.session.admin == 1"}
										<p id="text_delete_{$text.id}" class="text_delete text-right"><i class="fa fa-close"></i></p>
										{/if}
										{if condition="$Think.session.admin == 1"}
											{if condition="$text.if_top > 0"}
											<button id="set_top_{$text.id}" name="set_top" class="btn btn-outline-primary active">设为置顶</button>
											{else/}
											<button id="set_top_{$text.id}" name="set_top" class="btn btn-outline-primary">设为置顶</button>
											{/if}
										{/if}
									</div>
									<p class="my-1"><strong>{$text.user.fullname}</strong></p>
									<p>{$text.create_time}</p>
								</div>
							</div>
							<div>
							{$text.content}
							</div>
							<hr class="my-1">
							<div class="row mt-3">
								<div class="col-md text-center"></div>
	  							<div class="col-md text-center"><a href="/index/text?text_id={$text.id}" class="text-dark a-notdecoration"><i class="fa fa-comment"></i>&nbsp;{$text.reply_num}</a></div>
	  						</div>
						</div>
					</div>
					{/foreach}
					<nav aria-label="Page navigation example">
					{$texts->render()}
					</nav>
				</div>
				{/notempty}
				{notempty name="replys"}
				<div class="tab-pane fade" id="reply" role="tabpanel" aria-labelledby="reply_tab">
					{foreach $replys as $reply}
					<div class="card my-4">
						<div class="card-body">
							<div class="media">
								<img src="__AVATOR__{$reply.user.avator_path}" class="img-circle img-md">
								<div class="media-body ml-2">
									<div class="float-right">
										{if condition="$reply.user.id == $Think.session.user_id or $Think.session.admin == 1"}
										<p id="reply_delete_{$reply.id}" class="text_delete text-right"><i class="fa fa-close"></i></p>
										{/if}
										<a href="#" class="fold badge badge-primary ml-3">收起</a>
									</div>
									<p class="my-1"><strong>{$reply.user.fullname}</strong></p>
									<p>{$reply.create_time}</p>									
								</div>
							</div>
							<div>
								<a href="/index/text?text_id={$reply.text.id}" class="text-dark a-notdecoration">
								{$reply.content}
								</a>
								<div class="border bg-light p-2 mt-2 h-25">
								{$reply.text.content}
								</div>
							</div>
						</div>
					</div>
					{/foreach}
					<nav aria-label="Page navigation example">
					{$replys->render()}
					</nav>
				</div>
				{/notempty}
			</div>
		</div>
		<div id="warning_model" class="modal" tabindex="-1" role="dialog">
			<div class="modal-dialog" role="document">
    			<div class="modal-content">
    				<p id="accept_param_id"></p>
    				<p id="accept_param_type"></p>
    				<div class="modal-header">
    					<h5>是否确认删除？</h5>
				        <p data-dismiss="modal" aria-label="Close"><i class="fa fa-close"></i></p>
    				</div>
    				<div class="modal-body">
    					<p>删除后内容将无法恢复</p>
    				</div>
    				<div class="modal-footer">
    					<button id="delect_button" type="button" class="btn btn-primary">确认删除</button>
    				</div>
    			</div>
    		</div>
		</div>
	</div>
</body>

<script type="text/javascript">
	$(function(){
		var tab_type = "{$tab_type}";
		if (tab_type == 'text') {
			$('#text_tab').tab('show');
		}
		if (tab_type == 'reply') {
			$('#reply_tab').tab('show');
		}
		$('#accept_param_id').hide();
		$('#accept_param_type').hide();
		$('button[name="set_top"]').click(function() {
			var button_id = $(this).attr('id');
			var start = button_id.lastIndexOf('_');
			var text_id = button_id.substring(start + 1);
			button_id = '#' + button_id;
			var if_top = $(button_id).hasClass('active');
			if (if_top) {
				$(button_id).removeClass('active');
			}
			else {
				$(button_id).addClass('active');
			}
			var set_top = $(button_id).hasClass('active');
			$.post("/index/person/setTopText", {
				'text_id': text_id,
				'set_top': set_top
			},
			function(result) {
				console.log(result);
				if(result.status == 'success') {
					toastr.success(result.message);
				}
				if(result.status == 'error') {
					toastr.error(result.message);
				}
			}, "json");
		});
		$('.text_delete').click(function() {
			var button_id = $(this).attr('id');
			var start = button_id.lastIndexOf('_');
			var content_id = button_id.substring(start + 1);
			var end = button_id.indexOf('_');
			var type = button_id.substring(0, end);
			$('#accept_param_id').html(content_id);
			$('#accept_param_type').html(type);
			$('#warning_model').modal('show');
		});

		$('#delect_button').click(function() {
			$('#warning_model').modal('hide');
			var content_id = $('#accept_param_id').html();
			var type = $('#accept_param_type').html();
			var url;
			if (type == 'text') {
				url = "/index/person/deleteText";
			}
			else {
				url = "/index/person/deleteReply";
			}
			$.post(url, {
				'content_id': content_id
			},
			function(result) {
				if (result.status == 'success') {
					toastr.success(result.message);
					setTimeout(function(){
						 $(location).attr('href', result.data);
					}, 1000);
      			}
				if (result.status == 'error') {
      				toastr.error(result.message);
      			}
			}, "json");
		});
		$('.fold').click(function() {
			event.preventDefault();
			var status = $(this).html();
			var parents_element = $(this).parents('.card-body');
			var fold_element = parents_element.find('.border');
			console.log(fold_element);
			if (status == '收起') {
				$(this).html('展开');
				fold_element.hide();
			}
			else {
				$(this).html('收起');
				fold_element.show();
			}
		});
	});
</script>